package com.example.win.android_banduyujia.http.response;

import com.example.win.android_banduyujia.entity.LoginInfEntity;
import com.example.win.android_banduyujia.entity.YugaProfileEntity;
import com.example.win.android_banduyujia.lib.datetime.DateTime;

/**
 * Created by Win on 2015/9/22.
 */
public class SigninResponse extends BaseHttpResponse {

     private signinInfo  payload;

    public signinInfo getPayload() {
        return payload;
    }

    public void setPayload(signinInfo payload) {
        this.payload = payload;
    }

    public class signinInfo{
        private String  id;
        private String  username;
        private String  createtime;
        private String  lastvisit;
        private String  lastaction;
        private String  superuser;
        private String  status;
        private String  url;
        private String  feedsUrl;
        private String  avatarUrl;
        private String  textname;
        private String  btnedit;
        private String  htmlUrl;
        private String  notification;
        private String  settings;
        private String  accessToken;

        private String   currser;
        private String   today;
        private Profile  profile;

        public String getTextname() {
            return textname;
        }

        public void setTextname(String textname) {
            this.textname = textname;
        }

        public String getBtnedit() {
            return btnedit;
        }

        public void setBtnedit(String btnedit) {
            this.btnedit = btnedit;
        }

        public String getSettings() {
            return settings;
        }

        public void setSettings(String settings) {
            this.settings = settings;
        }

        public String getLastaction() {
            return lastaction;
        }

        public void setLastaction(String lastaction) {
            this.lastaction = lastaction;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public String getLastvisit() {
            return lastvisit;
        }

        public void setLastvisit(String lastvisit) {
            this.lastvisit = lastvisit;
        }

        public String getSuperuser() {
            return superuser;
        }

        public void setSuperuser(String superuser) {
            this.superuser = superuser;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getFeedsUrl() {
            return feedsUrl;
        }

        public void setFeedsUrl(String feedsUrl) {
            this.feedsUrl = feedsUrl;
        }

        public String getAvatarUrl() {
            return avatarUrl;
        }

        public void setAvatarUrl(String avatarUrl) {
            this.avatarUrl = avatarUrl;
        }

        public String getHtmlUrl() {
            return htmlUrl;
        }

        public void setHtmlUrl(String htmlUrl) {
            this.htmlUrl = htmlUrl;
        }

        public String getNotification() {
            return notification;
        }

        public void setNotification(String notification) {
            this.notification = notification;
        }

        public String getAccessToken() {
            return accessToken;
        }

        public void setAccessToken(String accessToken) {
            this.accessToken = accessToken;
        }

        public String getCurrser() {
            return currser;
        }

        public void setCurrser(String currser) {
            this.currser = currser;
        }

        public String getToday() {
            return today;
        }

        public void setToday(String today) {
            this.today = today;
        }

        public Profile getProfile() {
            return profile;
        }

        public void setProfile(Profile profile) {
            this.profile = profile;
        }
    }

    public class Profile{
        private String user_id;
        private String realname;
        private int sex;
        private int birthday;
        private String first;
        private String uploadPicture;
        private String scope;
        private String area;
        private String venues;

        public String getUser_id() {
            return user_id;
        }

        public void setUser_id(String user_id) {
            this.user_id = user_id;
        }

        public String getRealname() {
            return realname;
        }

        public void setRealname(String realname) {
            this.realname = realname;
        }

        public int getSex() {
            return sex;
        }

        public void setSex(int sex) {
            this.sex = sex;
        }

        public int getBirthday() {
            return birthday;
        }

        public void setBirthday(int birthday) {
            this.birthday = birthday;
        }

        public String getFirst() {
            return first;
        }

        public void setFirst(String first) {
            this.first = first;
        }

        public String getUploadPicture() {
            return uploadPicture;
        }

        public void setUploadPicture(String uploadPicture) {
            this.uploadPicture = uploadPicture;
        }

        public String getScope() {
            return scope;
        }

        public void setScope(String scope) {
            this.scope = scope;
        }

        public String getArea() {
            return area;
        }

        public void setArea(String area) {
            this.area = area;
        }

        public String getVenues() {
            return venues;
        }

        public void setVenues(String venues) {
            this.venues = venues;
        }
    }

    @Override
    public Object saveInfo(BaseHttpResponse response) {
        return responseToLocal(response);
    }

    private LoginInfEntity responseToLocal(BaseHttpResponse response) {
        signinInfo  signin = ((SigninResponse)response).getPayload();
        Profile    profile = signin.getProfile();

        LoginInfEntity loginLocal = new LoginInfEntity();
        YugaProfileEntity yugaEntity = new YugaProfileEntity();

        loginLocal.setID(signin.getId());
        loginLocal.setNickName(signin.getUsername());
        loginLocal.setCreateTime(new DateTime(signin.getCreatetime(), false));
        loginLocal.setLastVisit(new DateTime(signin.getLastvisit(), false));
        loginLocal.setLastAction(new DateTime(signin.getLastaction(), false));
        loginLocal.setSuperUser(signin.getSuperuser());
        loginLocal.setStatus(Integer.valueOf(signin.getStatus()));
        loginLocal.setUrl(signin.getUrl());
        loginLocal.setFeedsUrl(signin.getFeedsUrl());
        loginLocal.setTextname(signin.getTextname());
        loginLocal.setBtnEdit(signin.getBtnedit());
        loginLocal.setAvatarUrl(signin.getAvatarUrl());
        loginLocal.setHtmlUrl(signin.getHtmlUrl());
        loginLocal.setCurrser(signin.getCurrser());
        loginLocal.setToday(signin.getToday());
        loginLocal.setNotification(signin.getNotification());
        loginLocal.setSettings(signin.getSettings());
        loginLocal.setAccessToken(signin.getAccessToken());

        yugaEntity.setUserId(profile.getUser_id());
        yugaEntity.setName(profile.getRealname());
        yugaEntity.setSex(profile.getSex());
        yugaEntity.setBirthday(profile.getBirthday());
        yugaEntity.setFirst(profile.getFirst());
        yugaEntity.setPhoto(profile.getUploadPicture());
        yugaEntity.setShouProjects(profile.getScope());
        yugaEntity.setShouAdrress(profile.getArea());
        yugaEntity.setShouGuan(profile.getVenues());
        yugaEntity.setYuga(profile.getVenues());

        loginLocal.setLoginProfile(yugaEntity);

        return  loginLocal;
    }
}
